package cn.woflcode.game.model;

import cn.woflcode.game.Global.Global;
import cn.woflcode.game.Global.ImageUtil;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * 游戏背景图
 */
public class Backgroud {
    private int y1 = 0;
    private int y2 = -Global.GAME_UI_HEIGHT;
    //获取游戏背景图片对象
    private BufferedImage image = ImageUtil.getImage("game_running");

    //画出图像的方法drawImage
    //获取画图方法，可以去Gamepanel中复制  改为public修饰  改名

    public void drawSelf(Graphics g) {
        //判断当前状态处于运行中
        if (Global.currentstate == Global.GameState.RUNNING) {
            //参数：图片对象 坐标 宽高 null
            g.drawImage(image, 0, y1, Global.GAME_UI_WIDTH, Global.GAME_UI_HEIGHT, null);
            g.drawImage(image, 0, y2, Global.GAME_UI_WIDTH, Global.GAME_UI_HEIGHT, null);
            //每次移动 y+1
            y1++;
            y2++;
            if (y1 == Global.GAME_UI_HEIGHT) {
                y1 = -Global.GAME_UI_HEIGHT;
            }
            if (y2 == Global.GAME_UI_HEIGHT) {
                y2 = -Global.GAME_UI_HEIGHT;
            }
        }else{
            //准备 暂停 结束
            g.drawImage(Global.currentstate.getImage(),0,0,Global.GAME_UI_WIDTH,Global.GAME_UI_HEIGHT,null);
        }
    }
}
